﻿package net.wangit.util;

import java.text.DecimalFormat;

public class NumberUtil {

	private static DecimalFormat df0 = new DecimalFormat("#0");
	private static DecimalFormat df1 = new DecimalFormat("#0.0");
	private static DecimalFormat df2 = new DecimalFormat("#0.00");
	private static DecimalFormat df3 = new DecimalFormat("#0.000");
	private static DecimalFormat df4 = new DecimalFormat("#0.0000");
	private static DecimalFormat df5 = new DecimalFormat("#0.00000");
	private static DecimalFormat df6 = new DecimalFormat("#0.000000");

	public NumberUtil() {
	}

	public static boolean isInt(String str) {
		return true;
	}

	public static int format0(double numStr) {
		return Integer.parseInt(df0.format(numStr));
	}

	public static int format0(String numStr) {
		if (!Checker.isEmpty(numStr))
			return format0(Double.parseDouble(numStr));
		else
			return 0;
	}

	public static double format1(double numStr) {
		return Double.parseDouble(df1.format(numStr));
	}

	public static double format1(String numStr) {
		if (!Checker.isEmpty(numStr))
			return format1(Double.parseDouble(numStr));
		else
			return 0.0D;
	}

	public static double format2(double numStr) {
		return Double.parseDouble(df2.format(numStr));
	}

	public static double format2(String numStr) {
		if (!Checker.isEmpty(numStr))
			return format2(Double.parseDouble(numStr));
		else
			return 0.0D;
	}

	public static double format3(double numStr) {
		return Double.parseDouble(df3.format(numStr));
	}

	public static double format3(String numStr) {
		if (!Checker.isEmpty(numStr))
			return format3(Double.parseDouble(numStr));
		else
			return 0.0D;
	}

	public static double format4(double numStr) {
		return Double.parseDouble(df4.format(numStr));
	}

	public static double format4(String numStr) {
		if (!Checker.isEmpty(numStr))
			return format4(Double.parseDouble(numStr));
		else
			return 0.0D;
	}

	public static double format5(double numStr) {
		return Double.parseDouble(df5.format(numStr));
	}

	public static double format5(String numStr) {
		if (!Checker.isEmpty(numStr))
			return format5(Double.parseDouble(numStr));
		else
			return 0.0D;
	}

	public static double format6(double numStr) {
		return Double.parseDouble(df6.format(numStr));
	}

	public static double format6(String numStr) {
		if (!Checker.isEmpty(numStr))
			return format6(Double.parseDouble(numStr));
		else
			return 0.0D;
	}

	public static double max(double array[]) {
		if (array == null)
			throw new IllegalArgumentException("The Array must not be null");
		if (array.length == 0)
			throw new IllegalArgumentException("Array cannot be empty.");
		double max = array[0];
		for (int j = 1; j < array.length; j++)
			if (array[j] > max)
				max = array[j];

		return max;
	}

	public static int max(int array[]) {
		if (array == null)
			throw new IllegalArgumentException("The Array must not be null");
		if (array.length == 0)
			throw new IllegalArgumentException("Array cannot be empty.");
		int max = array[0];
		for (int j = 1; j < array.length; j++)
			if (array[j] > max)
				max = array[j];

		return max;
	}

	public static double min(double array[]) {
		if (array == null)
			throw new IllegalArgumentException("The Array must not be null");
		if (array.length == 0)
			throw new IllegalArgumentException("Array cannot be empty.");
		double min = array[0];
		for (int i = 1; i < array.length; i++)
			if (array[i] < min)
				min = array[i];

		return min;
	}

	public static int min(int array[]) {
		if (array == null)
			throw new IllegalArgumentException("The Array must not be null");
		if (array.length == 0)
			throw new IllegalArgumentException("Array cannot be empty.");
		int min = array[0];
		for (int j = 1; j < array.length; j++)
			if (array[j] < min)
				min = array[j];

		return min;
	}

}
